﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using System.Web;
namespace LIB
{
   public  class RewriteURL
    {
       public static string  getRealUrl(string virtualURL,string path)
       {
           string s="";
           List<Rule> myrules = new List<Rule>();
           
           myrules = XMLSerialization.DeserializeFromXML<Rule>(path);
           for (int i = 0; i < myrules.Count; i++)
           {
               Regex rg = new Regex(myrules[i].VirtualUrl);
               if (rg.IsMatch(virtualURL))
               {
                   
                   s = Regex.Replace(virtualURL,myrules[i].VirtualUrl,myrules[i].RealUrl);
                   return s;
               }
               
           }
           return "Error.htm";
       }
    }
  public  class Rule
   {

       [XmlElement("Url")]
       public string VirtualUrl
       { get; set; }

       [XmlElement("Rewrite")]
       public string RealUrl
       { get; set; }
   }
}
